import { getUserToken,removeUserToken } from '@/utils/auth';

const state = {
  userToken: getUserToken(),
}

const mutations = {
  SET_USER_TOKEN: (state, token) => {
    console.log("modules user SET_USER_TOKEN :",token);
    state.userToken = token
  },
}

const actions = {


  setUserToken({ commit }, userToken) {
    return new Promise((resolve, reject) => {
      commit('SET_USER_TOKEN', userToken)
      resolve(userToken);
    });
  },

  resetUserToken({ commit }) {
    return new Promise(resolve => {
      console.log("user store resetUserToken>>>");
      commit('SET_USER_TOKEN', '')
      commit('SET_ROLES', [])
      removeUserToken()
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
